<!--#include file="inc/AspCms_SettingClass.asp" -->

<%
dim action : action=getForm("action","get")
if action = "login" then
	dim UserName,Password,sql,code,Rs,atype
	UserName = filterPara(getForm("username","post"))
	atype    = getForm("atype","post")
	Password = md5(getForm("Password","post"),16)
	code     = getForm("code","post")
	if admincode = 1 then
		if code <> Session("Code") then	alertMsgAndGo "您填写的验证码错误!","-1"
	end if
	if isOutSubmit then alertMsgAndGo "非法外部提交被禁止","-1"

	sql = "select count(1) from {prefix}User where LoginName = '"&UserName&"' and Password='"&Password&"'"
	Dim rsObj : Set rsObj=Conn.Exec(sql,"r1")
	if rsObj(0)=1 then
		
		
		Set rsObj = Conn.Exec("select IsAdmin, GroupStatus,GroupName, UserStatus, UserID, b.GroupMenu,GroupSort, LanguageID,adminrand from {prefix}User as a, {prefix}UserGroup as b where LoginName='"&UserName&"' and a.GroupID=b.GroupID","r1")	
		if not rsObj.Eof Then
			if rsObj("IsAdmin")     <> 1 then alertMsgAndGo"对不起，你不是管理员！","-1"
			if rsObj("GroupStatus") <> 1 then alertMsgAndGo"对不起，您所在用户组已被禁用！","-1"
			if rsObj("UserStatus")  <> 1 then alertMsgAndGo"对不起，您的账号已被禁用！","-1"
			Session("adminName")    = UserName
			Session("GroupName")    = rsObj("GroupName")
			Session("adminpwd")     = getForm("Password","post")
			Session("adminId")      = rsObj("UserID")
			Session("groupMenu")    = repnull(rsObj("GroupMenu"))
			Session("GroupSort")    = repnull(rsObj("GroupSort"))
			Session("sitepath")     = SitePath
			'查找
			dim LanguageID
			LanguageID = rsObj("LanguageID")

			if isnul(LanguageID) then 				
				set rs = conn.exec("select LanguageID,LanguagePath,Alias,IsDefault from {prefix}Language where IsDefault=1","exe")
				if rs.eof then					
					echoErr err_15,15,"没有设置默认语言"
				else
					LanguageID = rs(0)
				end if
			else 	
				set rs = conn.exec("select LanguageID,LanguagePath,Alias,IsDefault from {prefix}Language where LanguageID="&LanguageID,"exe")				
				LanguageID = rs(0)	
			end if 
			randomize
			dim randnum
			randnum = clng(rnd*99999999)
			Conn.Exec"update {prefix}User set adminrand='"&randnum&"' where UserID="&rsObj("UserID"),"exe"	
			Session("adminrand")     = randnum
			Session("languageID")    = LanguageID			
			Session("LanguagePath")  = rs("LanguagePath")
			Session("LanguageAlias") = rs("Alias")
			session("IsDefault")     = rs("IsDefault")

			rs.close : set rs = nothing
			Conn.Exec"update {prefix}User set LastLoginTime='"&now()&"',LastLoginIP='"&getIp()&"',LoginCount=LoginCount+1 where UserID="&rsObj("UserID"),"exe"	
			if atype = 0 then		
			response.Redirect("index.asp")
			else
			response.Redirect("index_user.asp")	
			end if
		end if
	else
		alertMsgAndGo "用户名或密码错误!","-1"
	end if
	rsObj.Close() : set rsObj=Nothing	
elseif action = "logout" then
	Session("adminName") = ""
	Session("adminId")   = ""
	Session("groupMenu") = ""
	Session("SceneMenu") = ""
	response.Redirect("login.asp"):response.End()
elseif action = "relog" then
	alertMsgAndGo "对不起,您的登录状态已经失效,请重新登录!","login.asp"
end if

<!-- 随机背景数量 -->
Dim ImgNum
Randomize
    ImgNum = Int((2 * Rnd) + 1)

%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>Aspcms网站管理系统</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />

<link href="css/timoo/uikit.min.css" rel="stylesheet">
<link href="css/timoo/login.css" rel="stylesheet">

<script src="js/timoo/jquery.min.js"></script>
<script src="js/timoo/uikit.min.js"></script>
<script src="js/timoo/uikit-icons.min.js"></script>
<script src="js/timoo/timoo.js"></script>

<script>
window.onload = function(){

	var txtUserName = document.getElementById("username");
	var txtPassword = document.getElementById("password");
	
	changeimg();
	
	var username = readCookie("username");
	
	if(username!=""){
	
		txtUserName.value = username;
		txtPassword.focus();
		
	} else txtUserName.focus();
	
	document.getElementById("code").value = "";
		
}
	
function changeimg(){ 
		
	document.getElementById('SeedImg').src='../inc/checkcode.asp?'+Math.random();
		
}
	
function writeCookie(name, value, hours){
	
	var expire = "";
		
	if(hours != null){
			
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
		
	}
		
	document.cookie = name + "=" + escape(value) + expire;
		
}
	
function readCookie(name){
	
	var cookieValue = "";
	var search      = name + "=";
		
	if(document.cookie.length > 0) { 
		
		offset = document.cookie.indexOf(search);
			
		if(offset != -1){ 
			
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
				
			if(end == -1) end = document.cookie.length;
				
				cookieValue = unescape(document.cookie.substring(offset, end))
					
		}
			
	}
		
	return cookieValue;
		
}
</script>
</head>
<body>

<div class="uk-flex uk-flex-center uk-flex-middle tm-login">
    <div class="background" style="background-image: url(tm-img/background/<% Response.Write ImgNum %>.jpg);"></div>
    <div class="main">
        <div class="container">
            <div class="uk-text-center title"><span>Aspcms网站后台管理中心</span></div>
            <div class="form">
                <form method="post" action="?action=login" onsubmit="writeCookie('username',this.username.value, 1)">
                    <input type="hidden" name="gotopage" value="/aspcms/index.asp">
                    <input type="hidden" name="dopost" value="login">
                    <div class="box">
                        <div class="list name">
                            <span class="subject">
                                <i class="icon" uk-icon="icon: users"></i>
                            </span>
                            <span class="input">
                                <input type="text" id="username" name="username" maxlength="20" placeholder="用户名">
                            </span>
                        </div>
                        <div class="list password">
                            <span class="subject">
                                <i class="icon" uk-icon="icon: lock"></i>
                            </span>
                            <span class="input">
                                <input type="password" id="password" name="password" maxlength="20" placeholder="密码">
                            </span>
                        </div>
                        <%if admincode=1 then%>
                        <div class="list code">
                            <span class="subject">
                                <i class="icon" uk-icon="icon: settings"></i>
                            </span>
                            <span class="input">
                                <input type="text" id="code" name="code" size="10" maxlength="4" placeholder="验证码">
                                <img src="../inc/checkcode.asp" id="SeedImg" alt="点我刷新" onclick="changeimg()">
                            </span>
                        </div>
                        <%end if%>
                        <div class="list">
                            <span class="uk-clearfix input">
                                <div class="uk-float-left back"><a href="/">返回首页</a></div>
                                
                                <label for="whole" class="uk-clearfix uk-float-right tm-transition">
                                    <span class="uk-float-left check">
                                        <i class="tm-transition icon" uk-icon="icon: check"></i>
                                    </span>
                                    <span class="uk-float-left">开发人员</span>
                                    <input id="whole" name="atype" type="radio" value="0" checked="checked" />
                                </label>
                                <label class="uk-clearfix uk-float-right tm-transition">
                                    <span class="uk-float-left check">
                                        <i class="tm-transition icon" uk-icon="icon: check"></i>
                                    </span>
                                    <span class="uk-float-left">维护人员</span>
                                    <input id="whole" name="atype" type="radio" value="1" checked="checked" />
                                </label>
                            </span>
                        </div>
                        <div class="list">
                            <span class="input">
                                <input name="submit" type="submit" value="登入" class="input" />
                            </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="uk-text-center copyright">
              后台管理系统 &copy;2023-2024
            </div>
            <div class="back"></div>
        </div>
    </div>
</div>
</body>
</html>
